<?php

// load configuration file
require_once('config/config.php');
// load error handling module
require_once('config/error_handler.php');

// Chat class that contains server-side chat functionality
class Chat {

    // database handler
    private $mMysqli;

    // constructor opens database connection
    function __construct() {
        // connect to the database
        $this->mMysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
    }

    // destructor closes database connection
    public function __destruct() {
        $this->mMysqli->close();
    }

    public function readNieuws() {
        $query = "SELECT * FROM nieuws ORDER BY id_nieuws DESC LIMIT 1 ";
        // execute the query
        $result = $this->mMysqli->query($query);

        // check to see if we have any results
        if ($result->num_rows) {
            // loop through all the fetched messages to build the result message
            while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
                echo "<h2>{$row['titel']}</h2><hr> " .
                "{$row['tekst']} <br>";
            }
            // close the database connection as soon as possible
            $result->close();
        }
    }
}
?>
